package com.mysiteforme.admin.dao;

import com.mysiteforme.admin.base.entity.Equipment;
import com.mysiteforme.admin.entity.DeviceInfo;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 设备信息描述表 Mapper 接口
 * </p>
 *
 * @author wangl
 * @since 2019-02-22
 */
public interface DeviceInfoDao extends BaseMapper<DeviceInfo> {

    @Select("SELECT id,dev_id,type,amount,range,alarms,IFNULL((select max(ligntningCount) from lightning_log where devEUI = equipment.eid and lightning_log.valid = '1111'),0) as total,e_status,online_time,remark,uid"
            + " FROM equipments where id = #{id}  and valid = 'N' ")
    public Equipment getEquipmentById(@Param("id") Integer id);


    @Select("<script>select equipments.dev_id,equipments.name from equipments where valid = 'N'  " +
            "and uid like (" +
            "select case u.competence " +
            "when 2 then '%'" +
            " when 3 then u.id " +
            " when 4 then u.parent_uid end as u_id " +
            " from users u where u.id = #{uid} limit 1 ) "
            + "</script>")
    public List<Map<String,String>> getUserEquipmentIdList(@Param("uid") Integer uid);
}
